package com.zzedu.app;

import com.zzedu.common.utils.DateUtils;
import com.zzedu.enmuns.ResponseCodeEnums;

import java.io.Serializable;

/**
 * 响应信息
 *
 * @param <T>
 */
public class BaseResponse<T> implements Serializable {
    /**
     * 响应数据
     */
    private T data;
    /**
     * 响应码 1-成功 2-失败 3-处理中 301 -请登录
     *
     */
    private Integer status;
    /**
     * 响应消息说明
     */
    private String message;

    /**
     * 服务器时间毫秒
     */
    private String serviceTime;

    public T getData() {
        return data;
    }

    private BaseResponse() {

    }

    public BaseResponse<T> setData(T data) {
        this.data = data;
        return this;
    }

    public Integer getStatus() {
        return status;
    }

    public BaseResponse<T> setStatus(Integer status) {
        this.status = status;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public BaseResponse<T> setMessage(String message) {
        this.message = message;
        return this;
    }

    public String getServiceTime() {
        return serviceTime;
    }

    public BaseResponse<T> setServiceTime(String serviceTime) {
        this.serviceTime = serviceTime;
        return this;
    }

    public static BaseResponse success(Object data) {
        return new BaseResponse().setData(data)
                .setServiceTime(DateUtils.getTime())
                .setStatus(ResponseCodeEnums.SUCCESS.getCode()).setMessage(ResponseCodeEnums.SUCCESS.getDesc());
    }

    public static BaseResponse success() {
        return new BaseResponse()
                .setServiceTime(DateUtils.getTime()).setStatus(ResponseCodeEnums.SUCCESS.getCode()).setMessage(ResponseCodeEnums.SUCCESS.getDesc());
    }

    public static BaseResponse fail() {
        return new BaseResponse()
                .setServiceTime(DateUtils.getTime()).setStatus(ResponseCodeEnums.FAIL.getCode()).setMessage(ResponseCodeEnums.FAIL.getDesc());
    }

    public static BaseResponse fail(String msg) {
        return new BaseResponse()
                .setServiceTime(DateUtils.getTime()).setStatus(ResponseCodeEnums.FAIL.getCode()).setMessage(msg);
    }

    public static BaseResponse fail(ResponseCodeEnums responseCodeEnums) {
        return new BaseResponse()
                .setServiceTime(DateUtils.getTime()).setStatus(responseCodeEnums.getCode()).setMessage(responseCodeEnums.getDesc());
    }

    public boolean isSuccess() {
        return status== ResponseCodeEnums.SUCCESS.getCode();
    }
}
